class Solution
{
public:
    int singleNumber(vector<int> &nums)
    {
        vector<int> bits(32);
        for (int num : nums)
        {
            for (int i = 0; i <= 31; ++i)
            {
                bits[i] += !!(num & (1 << i));
            }
        }
        int result = 0;
        for (int i = 0; i <= 31; ++i)
        {
            result |= (bits[i] % 3) << i;
        }
        return result;
    }
};